# -*- coding: utf-8 -*-
# @Time : 2022/6/20 11:38
# @Author : cheney, raoxiaoyang
# @File : sensorController.py
# @Software: PyCharm
# @Site: www.cheney.cc

from pi.dao.sensorDao import sensorDao
from pi.dao.confDao import get_table
from pi.controller.sensor.temperature.temperatureSensor import *
from pi.controller.sensor.light.lightSensor import *


class sensorController:
    sensor_table = {}
    senDao = sensorDao()

    SENSOR_TEM = 1
    SENSOR_LIG = 2

    def __init__(self):
        self.sensor_table = get_table()
        self.tempSonsor = SensorTem()
        self.ligSensor = SensorLig()

    def get_data(self, sensor_id) -> list:
        """
        获取单个传感器数据（根据传感器id）
        :param sensor_id:
        :return:
        """
        if sensor_id == self.SENSOR_TEM:  # 温度传感器
            return [self.tempSonsor.printTemperature()]
        elif sensor_id == self.SENSOR_LIG:
            return [self.ligSensor.printLight()]

    def get_data_all(self) -> list:
        """
        获得所有传感器到数据，顺序和self.sensor_list相同
        :return:
        """
        #data1 = self.tempSonsor.printTemperature()
        #time.sleep(t_time)
        data2 = self.ligSensor.printLight()
        return [data2, ]

    # def get_distance_3(self):
    #     """
    #     避障的时候用，获取左 中 右三个方向的距离，其中左右是红外，中间是超声波（需要计算）
    #     :return: 比如 10,50,20 表示三个方向距离分别为10,50,20
    #     """
    #     # todo:怎么获取三个传感器对应的编号 ？ 并且在dao里面添加对应的函数
    #     distance_left = 10
    #     distance_head = 50
    #     distance_right = 20
    #
    #     return distance_left, distance_head, distance_right

    def sensor_up(self, sensor_id: list):
        """
        开传感器，列表内的所有传感器
        :param sensor_id:
        :return:
        """
        pass

    def sensor_down(self, sensor_id: list):
        """
        关传感器，列表内的所有传感器
        :param sensor_id:
        :return:
        """
        pass
